//
//  WXApiManager.m
//  SDKSample
//
//  Created by Jeason on 16/07/2015.
//
//

#import "WXApiManager.h"

@implementation WXApiManager

#pragma mark - LifeCycle
+(instancetype)sharedManager {
    static dispatch_once_t onceToken;
    static WXApiManager *instance;
    dispatch_once(&onceToken, ^{
        instance = [[WXApiManager alloc] init];
    });
    return instance;
}

#pragma mark - WXApiDelegate
- (void)onResp:(BaseResp *)resp {
    if([resp isKindOfClass:[PayResp class]]){

        /*
        WXSuccess           = 0,     成功
        WXErrCodeCommon     = -1,       普通错误类型
        WXErrCodeUserCancel = -2,    用户点击取消并返回
        WXErrCodeSentFail   = -3,    发送失败
        WXErrCodeAuthDeny   = -4,    授权失败
        WXErrCodeUnsupport  = -5,    微信不支持
        */

        //支付返回结果，实际支付结果需要去微信服务器端查询
        NSLog(@"resp=%@",resp);

        [[NSNotificationCenter defaultCenter] postNotificationName:@"wxPayResult" object:@{@"errCode":@(resp.errCode)}];

    } else {
        
    }

    if ([resp isKindOfClass:[SendAuthResp class]]) {   //授权登录的类。
        if (resp.errCode == 0) {  //成功。
            SendAuthResp *resp2 = (SendAuthResp *)resp;

            [[NSNotificationCenter defaultCenter] postNotificationName:@"wxLogin" object:@{@"code":resp2.code}];

        }else{ //失败
            NSLog(@"授权失败");
        }
    }
}

- (void)onReq:(BaseReq *)req {

}

@end
